Micron Document
Livres et Wikis | Archives | Info


Java syntax
part 4/23 Β· 86.1 KB total
layout: Wide Β· Narrow Β· Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
The separators { and } signify a code block and a new scope. Class members and the body of a method are examples of what can live inside these braces in various contexts.

Inside of method bodies, braces may be used to create new scopes, as follows:

void doSomething() {
int a;
{
int b;
a = 1;
}
a = 2;
b = 3; // Illegal because the variable b is declared in an inner scope..
}

Comments

Java has three kinds of comments: traditional comments, end-of-line comments and documentation comments.

Traditional comments, also known as block comments, start with /* and end with */, they may span across multiple lines. This type of comment was derived from C and C++.

/* This is a multi-line comment.
It may occupy more than one line. */

End-of-line comments start with // and extend to the end of the current line. This comment type is also present in C++ and in modern C.

// This is an end-of-line comment

Documentation comments in the source files are processed by the Javadoc tool to generate documentation. This type of comment is identical to traditional comments, except it starts with /** and follows conventions defined by the Javadoc tool. Technically, these comments are a special kind of traditional comment and they are not specifically defined in the language specification.

/**
* This is a documentation comment.
*
* @author John Doe
*/

Universal types

Classes in the package java.lang are implicitly imported into every program, as long as no explicitly-imported types have the same names. Important ones include:

java.lang.Object

java.lang.Object is Java's top type. It is implicitly the superclass of all classes that do not declare any parent class (thus all classes in Java inherent from Object. All values can be converted to this type, although for primitive values this involves autoboxing.

java.lang.String

java.lang.String is Java's basic string type. Immutable. Some methods treat each UTF-16 code unit as a "character", but methods to convert to an int[] that is effectively UTF-32 are also available.

java.lang.Throwable

java.lang.Throwable is supertype of everything that can be thrown or caught with Java's throw and catch statements.


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────